# coding=utf-8
import sys
import os
import re
import matplotlib.pyplot as plt
import numpy as np


def parse(files):
    all_data = []
    for fname in files:
        line = open(fname).readline()
        data = line.strip().split(',')
        data_items = list(map(lambda x: float(x.split('=')[1]), data))
        all_data.append(data_items)

    all_data = np.asarray(all_data)
    return all_data


input_paths = sys.argv[1:]

# get 2
uscores = parse(input_paths)

clusters = ["and", "but", "because", "if", "when", "before", "though", "so", "unknown"]
# buy_number_male = [6, 7, 6, 1, 2]
# buy_number_female = [9, 4, 4, 5, 6]
labels = ['ConvS2S', 'FConvS2S', 'GPT2', 'GPT2P', 'TLM+Discourse']

bar_width = 0.12  # 条形宽度
index_male = np.arange(len(clusters))  # 男生条形图的横坐标

number = 8
# clusters_temp = clusters[:8]
# index_male = index_male[:8]
# uscores_temp = uscores[:, :8]
index_male = index_male[[0,4,8]]
uscores_temp = uscores[:, [0, 4, 8]]
clusters = [clusters[0], clusters[4], clusters[8]]


fontsize = 8
plt.figure(figsize=(4, 3))
for i in range(5):
    index = index_male + i * bar_width
    plt.bar(index, height=uscores_temp[i], width=bar_width, label=labels[i])


plt.legend(fontsize=fontsize)
plt.xticks(index_male + (4 * bar_width)/2, clusters, fontsize=7)
plt.yticks(fontsize=7)
plt.ylabel('percentage', fontsize=fontsize)
plt.title('Percentage of Each Discourse Relation', fontsize=fontsize)

# plt.show()
plt.savefig('all_discourse4.pdf')
